package net.hn.hnms.biz.energy.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.energy.domain.WaterRecord;
import net.hn.hnms.biz.energy.request.WaterRecordReq;
import net.hn.hnms.biz.energy.service.WaterRecordService;
import net.hn.hnms.biz.energy.vo.WaterRecordVo;
import net.hn.hnms.biz.energy.vo.WaterTotalVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "供水台账", tags = {"供水台账"})
@RestController
@RequestMapping("/water/record")
public class WaterRecordController extends BaseController {

    @Autowired
    private WaterRecordService waterRecordService;

    /**
     * 新增用水结算
     */
    @ApiOperation("新增供水台账")
    @SaCheckPermission("water:record:add")
    @PostMapping("/add")
    @Log(title = "新增供水台账", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody WaterRecordReq waterRecordReq) {
        return toAjax(waterRecordService.insert(waterRecordReq));
    }

    /**
     * 删除用水结算
     */
    @ApiOperation("删除供水台账")
    @SaCheckPermission("water:record:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除供水台账", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        waterRecordService.updateDeleteByIds(idList);
        return R.ok();
    }

    /**
     * 更新供水台账
     */
    @ApiOperation("更新供水台账")
    @SaCheckPermission("water:record:update")
    @PostMapping("/update")
    @Log(title = "更新供水台账", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody WaterRecordReq waterRecordReq) {
        waterRecordService.updateById(waterRecordReq);
        return R.ok();
    }

    /**
     * 获取供水台账详情
     */
    @ApiOperation("获取供水台账详情")
//    @SaCheckPermission("dispatch:keepwatch:detail")
    @GetMapping("/{id}")
    public R<WaterRecord> detail(@PathVariable("id") String id) {
        return R.ok(waterRecordService.selectDetailById(id));
    }

    /**
     * 获取供水台账列表
     */
    @ApiOperation("获取供水台账列表")
//    @SaCheckPermission("plan:drivage:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<WaterRecordVo>> page(WaterRecordReq waterRecordReq, PageQuery pageQuery) {
        return R.ok(waterRecordService.selectPageList(waterRecordReq, pageQuery));
    }

    /**
     * 统计总数
     */
    @ApiOperation("统计总数")
//    @SaCheckPermission("dispatch:keepwatch:detail")
    @GetMapping("/total")
    public R<WaterTotalVo> getTotal(WaterRecordReq waterRecordReq) {
        return R.ok(waterRecordService.getTotal(waterRecordReq));
    }


}
